package com.siberhus.easyexecutor;

import java.util.HashMap;
import java.util.Map;

public class CronEntries {
	
	private static final Map<String, String> ENTRY_MAP;
	
	static{
		ENTRY_MAP = new HashMap<String, String>();
		ENTRY_MAP.put("yearly", "0 0 1 1 *");
		ENTRY_MAP.put("annually", "0 0 1 1 *");
		ENTRY_MAP.put("monthly", "0 0 1 * *");
		ENTRY_MAP.put("weekly", "0 0 * * 0");
		ENTRY_MAP.put("daily", "0 0 * * *");
		ENTRY_MAP.put("midnight", "0 0 * * *");
		ENTRY_MAP.put("hourly", "0 * * * *");
	}
	
	public static String resolveEntry(String entry){
		if(entry==null){
			throw new IllegalArgumentException("Cron Entry is required.");
		}
		entry = entry.trim();
		if(entry.startsWith("@")){
			String cronExpression = ENTRY_MAP.get(entry.substring(1));
			if(cronExpression!=null){
				return cronExpression;
			}else{
				throw new IllegalArgumentException("Cron Entry: "+entry+" was not mapped.");
			}
		}
		return entry;
	}
	
}
